package com.cool.shark.controller;

import com.cool.shark.pojo.dto.AddressAddDto;
import com.cool.shark.pojo.vo.AddressByIdVo;
import com.cool.shark.service.AddressService;
import com.cool.shark.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Name: AddressController
 * @Author: 西风残叶
 * @Date: 2024/4/28 19:00
 * @Version: 1.0
 * @TODO: TODO
 */
@RestController
@Slf4j
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService service;

    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody AddressAddDto addressAddDto) {
        log.info("新增地址");
        service.addAddress(addressAddDto);
        return JsonResult.ok();
    }

    @GetMapping("/selectByUserId")
    public JsonResult<List<AddressByIdVo>> listSelectById(@Param("userId") Long userId) {
        log.info("查询地址,参数:{}",userId);
        List<AddressByIdVo> list = service.listSelectById(userId);
        return JsonResult.ok(list);
    }
}
